#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Core Class Library
 * Version 2.00
 * 
 * Debug Managed Methods API Class
 *		Defines and supplies the managed wrappers for the Debugging API.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
#include "ContinueStatus.h"
#include "DisposableObjectBase.h"

using namespace System;
using namespace System::IO;
using namespace System::Runtime::InteropServices;

namespace Adaptive
{
	namespace Win32
	{
		namespace Debugging
		{
			/// <summary>
			/// Defines and supplies the managed wrappers for the Debugging API.
			/// </summary>
			public ref class ManagedDebug sealed 
			{
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static ManagedDebug();

			public:
				/// <summary>
				/// Enables a debugger to continue a thread that previously reported a debugging event.
				/// </summary>
				/// <param name="processId">
				/// A handle to the process to continue.
				/// </param>
				/// <param name="threadId">
				/// A handle to the thread to continue. The combination of process identifier and thread 
				/// identifier must identify a thread that has previously reported a debugging event.
				/// </param>
				/// <param name="continueStatus">
				/// The options to continue the thread that reported the debugging event.
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns <b>false</b>.
				/// </returns>
				static bool ContinueDebug(int processId, int threadId, ContinueStatus continueStatus);
				/// <summary>
				/// Enables a debugger to continue a thread that previously reported a debugging event.
				/// </summary>
				/// <param name="processId">
				/// A handle to the process to continue.
				/// </param>
				/// <param name="threadId">
				/// A handle to the thread to continue. The combination of process identifier and thread identifier must identify a thread that has previously reported a debugging event.
				/// </param>
				/// <param name="continueStatus">
				/// The options to continue the thread that reported the debugging event.
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns <b>false</b>.
				/// </returns>
				static bool ContinueDebug(IntPtr^ processId, IntPtr^ threadId, ContinueStatus continueStatus);
				/// <summary>
				/// Enables a debugger to attach to an active process and debug it.
				/// </summary>
				/// <param name="processId">
				/// The identifier for the process to be debugged. 
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns <b>false</b>.
				/// </returns>
				static bool DebugActiveProcess(int processId);
				/// <summary>
				/// Enables a debugger to attach to an active process and debug it.
				/// </summary>
				/// <param name="processId">
				/// The identifier for the process to be debugged. 
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns <b>false</b>.
				/// </returns>
				static bool DebugActiveProcess(IntPtr^ processId);
				/// <summary>
				/// Stops the debugger from debugging the specified process.
				/// </summary>
				/// <param name="processId">
				/// The identifier for the process to be debugged. 
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns <b>false</b>.
				/// </returns>
				static bool DebugActiveProcessStop(IntPtr^ processId);
				/// <summary>
				/// Causes a breakpoint exception to occur in the current process. 
				/// This allows the calling thread to signal the debugger to handle 
				/// the exception.
				/// </summary>
				static void BreakDebug();
				/// <summary>
				/// Causes a breakpoint exception to occur in the specified process. This 
				/// allows the calling thread to signal the debugger to handle the 
				/// exception.
				/// </summary>
				/// <param name="processId">
				/// A handle to the process.
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>; otherwise,
				/// returns zero.
				/// </returns>
				static bool DebugBreakProcess(IntPtr^ processId);
				/// <summary>
				/// Sets the action to be performed when the debugging thread exits.
				/// </summary>
				/// <param name="killOnExit">
				/// If this parameter is <b>true</b>, the debug thread will kill the 
				/// process being debugged on exit. Otherwise, the debug thread will 
				/// detach from the process being debugged on exit. 
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>.
				/// </returns>
				static bool DebugSetProcessKillOnExit(bool killOnExit);
				/// <summary>
				/// Transfers execution control to the debugger. The behavior of the 
				/// debugger thereafter is specific to the type of debugger used.
				/// </summary>
				/// <param name="exitCode">
				/// The error code associated with the exit.
				/// </param>
				static void FatalExit(int exitCode);
				/// <summary>
				/// Flushes the instruction cache for the specified process.
				/// </summary>
				/// <param name="processHandle">
				/// A handle to a process whose instruction cache is to be flushed.
				/// </param>
				/// <param name="baseAddressPointer">
				/// A pointer to the base of the region to be flushed. This parameter can be <b>null</b>. 
				/// </param>
				/// <param name="size">
				/// The size of the region to be flushed if the lpBaseAddress parameter is not NULL, in bytes.
				/// </param>
				/// <returns>
				/// If the function succeeds, the return value is <b>true</b>.
				/// </returns>
				static bool FlushInstructionCache(IntPtr^ processHandle, int^ baseAddressPointer, int size);
				/// <summary>
				/// Determines whether the calling process is being debugged by a user-mode debugger.
				/// </summary>
				/// <returns>
				/// The current process is running in the context of a debugger, the return value is <b>true</b>; 
				/// otherwise, the value is <b>false</b>.
				/// </returns>
				static bool IsDebuggerPresent();
				/// <summary>
				/// Sends a string to the debugger for display.
				/// </summary>
				/// <param name="outputString">
				/// The null-terminated string to be displayed.
				/// </param>
				static void OutputDebugString(String^ outputString);
			};
		}
	}
}
